<?php 
function set_activiteiten_tabel($result, $eerstVolgendeActiviteit, $legenda=null, $bbcode=null, $selecteren=null, $wijzigen=null, $verwijderen=null, $aanwezigheidZichtbaar=null, $aanwezigheidSelecteren=null, $compact=null) {
	/*
	 * De tabel wordt aangemaakt
	 */
	$color = true;
	echo "<table class='content'>";
		echo "<tr class='normaal".($color ? "" : " alternate")."'>";	
			if(isset($selecteren)) {			echo "<th class='col_selecteren'>&nbsp;</th>";}
			//if(isset($wijzigen)) {				echo "<th class='col_wijzigen'>&nbsp;</th>";}
			//if(isset($verwijderen)) {			echo "<th class='col_verwijderen'>&nbsp;</th>";}
			if(isset($aanwezigheidZichtbaar)) {	echo "<th class='col_aanwezigheid'>&nbsp;</th>";}
			if(isset($aanwezigheidSelecteren)) {echo "<th class='col_aanwezigheid_selecteren'>&nbsp;</th>";}
			if(empty($compact)) {
				echo "<th class='col_datum'>Datum</th>";
			}
			echo "<th>Tijd</th>
				<th class='col_training_icon'>&nbsp;</th>
				<th class='col_activiteit'>Activitet</th>";
			if(empty($compact)) {
				if(isset($bbcode)) {	echo "<th class='col_info' colspan='2'>Info</th>";}
				else {					echo "<th class='col_aflasting'>Info</th>";}
			}
		echo "</tr>";
	
	//DE RIJEN OPHALEN UIT DE QUERY OF KOPIEREN VAN DE RESULT VARIABELE
	if(is_array($result)) {
		$rows = $result;
	}else if($result <> null && $result->rowCount() > 0) {
		$rows = $result->fetchAll(PDO::FETCH_ASSOC);
	}else {
		$rows = null;
	}	
	
	foreach($rows AS $row) {
		//echo "<div class='agenda_post".($row['soort'] == 1 ? " training" : " overig").(isset($row['bericht']) ? " tooltip" : "")."' rel='".$row['bericht']."'>";
		($color ? $color = false: $color = true);
		echo "<tr id='A".$row['agendaId']."' class='normaal".($eerstVolgendeActiviteit == $row['agendaId'] ? " selected" : ($color ? "" : " alternate"))."'>";
			if(isset($selecteren)) {			echo "<td><img class='popup_trigger' style='cursor:pointer; vertical-align:middle;' src='/images/icons/pijl_rechts.png' rel='".$row['agendaId']."'></td>";}
			//if(isset($wijzigen)) {				echo "<td><img class='popup_trigger_wijzigen' style='cursor:pointer; vertical-align:middle;' src='/images/icons/wijzigen.png' rel='".$row['agendaId']."'></td>";}
			//if(isset($verwijderen)) {			echo "<td><img class='popup_trigger_verwijderen' style='cursor:pointer; vertical-align:middle;' src='/images/icons/verwijderen.png' rel='".$row['agendaId']."'></td>";}
			if(isset($aanwezigheidZichtbaar)) {	
				if(empty($row['afmelden']) || $row['afmelden'] == 1) {	echo "<td class='".(empty($row['afwezig']) || $row['afwezig'] == '1' ? "aanwezig" : ($row['afwezig'] == '2' ? "onbekend" : "afwezig"))."'>&nbsp;</td>";}
				else if($row['afmelden'] == 2) {						echo "<td class='".(empty($row['afwezig']) || $row['afwezig'] == '3' || $row['afwezig'] == '4' ? "afwezig" : ($row['afwezig'] == '2' ? "onbekend" : "aanwezig"))."'>&nbsp;</td>";}
			}
			if(isset($aanwezigheidSelecteren)) {
				echo "<td><span".(isset($row['reden']) ? " rel='".$row['reden']."'" : "");
				//Afmelden is niet mogelijk
				if(empty($row['afmelden'])) {	echo " class='tooltip_disappear' title='Afmelden is niet mogelijk'>-</span>";}
				//Afmelden is mogelijk
				else if($row['afmelden'] == 1) {echo " class='icon_font in_table selectable ".(isset($row['reden']) ? "dark_font" : "light_font")."'>".(empty($row['afwezig']) || $row['afwezig'] == '1' ? "&#x44;" : ($row['afwezig'] == '2' ? "&#x48;" : "&#x46;"))."</span>";}
				//Aanmelden is mogelijk
				else {							echo " class='icon_font in_table selectable ".(isset($row['reden']) ? "dark_font" : "light_font")."'>".(empty($row['afwezig']) || $row['afwezig'] == '3' ? "&#x46;" : ($row['afwezig'] == '2' ? "&#x48;" : "&#x44;"))."</span>";}
				echo "</td>";
			}
			// DATUM
			if(empty($compact)) {
				//echo "<td class='col_datum'><div class='table_selecter icon_font'><a href='/extra/agenda/info.php?id=".$row['agendaId']."'>&#x41;</a></div><span class='table_selecter_td'>".getDagWeekString(date('w', strtotime($row['datum'])), true).". ".date('d-m', strtotime($row['datum']))."</span></td>";
				echo "<td class='col_datum'><div class='table_selecter".(empty($wijzigen) ? "" : " table_dubbel_selecter")." icon_font'>".(empty($wijzigen) ? "" : "<a href='/extra/agenda/wijzigen.php?id=".$row['agendaId']."'>&#x23;</a>")."<a href='/extra/agenda/info.php?id=".$row['agendaId']."'>&#x41;</a></div><span class='table_selecter_td'>".getDagWeekString(date('w', strtotime($row['datum'])), true).". ".date('d-m', strtotime($row['datum']))."</span></td>";
			}
    		// TIJD
    		echo "<td>";
    			echo date('H:i', strtotime($row['datum']))."</td>";
    		// TRAINING ICON
    		echo "<td class='".($row['soort'] == 1 ? "training" : "overig")."'>&nbsp;</td>";
    		// ACTIVITEIT
    		echo "<td class='col_activiteit'><p class='ellipsis'>";
    			echo $row['gebeurtenis']."</p></td>";
    		// INFO
    		//if(empty($compact)) {
    			//if(isset($bbcode)) {echo "<td class='col_info".(isset($row['bericht']) ? " tooltip".(empty($row['symbool']) ? " information" : " alert") : "")."' title='".$bbcode->parse($row['bericht'])."'>&nbsp;</td>";}
    			//echo "<td class='col_aflasting".($row['afgelast'] == '1' ? " cancel" : "")."'>&nbsp;</td>";
    		//}
			// OPMERKING EN INFO
			if(isset($row['bericht'])) {
				//Er is een bericht geschreven en laat eventueel de verzameltijd zien
				echo "<td class='tooltip col_info' title='".$bbcode->parse($row['bericht'])."'>";
				echo "<span class='icon_font in_table'>".(empty($row['symbool']) ? "&#x3c;" : "&#x3d;")."</span></td>";
			}else {
				//Er is geen bericht geschreven
				echo "<td class='col_info'>&nbsp;</td>";
			}
			
			// AFGELASTING
			echo "<td class='col_aflasting'><span class='icon_font in_table".(empty($row['verregend']) && empty($row['afgelast']) ? ($row['soort'] == 1 ? "'>&#x4d;" : ($row['soort'] == 2 ? "'>&#x4e;" : "'>&#x38;")) : " icon_big'>".(empty($row['verregend']) ? "&#x3b;" : "&#x40;"))."</span></td>";
    	echo "</tr>";
	}
	echo "</table>";
}